package com.danco.training.zaneuskaya.domain;

import java.io.Serializable;
import java.util.Date;
import java.util.HashSet;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

/**
 * @author Zaneuskaya Aliaksandra
 *
 */
@Entity
@Table(name = "event")
public class Event implements Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = -1826254350034824994L;

	@Id
	@GeneratedValue
	@Column(name = "event_id")
	private Integer eventId;

	@Column(name = "event_title")
	private String eventTitle;

	@Column(name = "event_start")
	@Temporal(value = TemporalType.TIMESTAMP)
	private Date eventStartDate;

	@Column(name = "event_end")
	@Temporal(value = TemporalType.TIMESTAMP)
	private Date eventEndDate;

	@Column(name = "event_description")
	private String eventDescription;

	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "organizer_fk", referencedColumnName = "user_id")
	private User organizer;

	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "country_fk", referencedColumnName = "country_id")
	private Country eventCountry;

	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "city_fk", referencedColumnName = "city_id")
	private City eventCity;

	@Column(name = "address")
	private String eventAddress;

	@Column(name = "event_access")
	@Enumerated(value = EnumType.ORDINAL)
	private EventAccess eventAccess;

	@ManyToMany(cascade = { CascadeType.ALL })
	@JoinTable(name = "user_event", joinColumns = { @JoinColumn(name = "event_fk") }, inverseJoinColumns = { @JoinColumn(name = "user_fk") })
	private Set<User> participants = new HashSet<User>();

	public Integer getEventId() {
		return eventId;
	}

	public void setEventId(Integer eventId) {
		this.eventId = eventId;
	}

	public String getEventTitle() {
		return eventTitle;
	}

	public void setEventTitle(String eventTitle) {
		this.eventTitle = eventTitle;
	}

	public Date getEventStartDate() {
		return eventStartDate;
	}

	public void setEventStartDate(Date eventStartDate) {
		this.eventStartDate = eventStartDate;
	}

	public Date getEventEndDate() {
		return eventEndDate;
	}

	public void setEventEndDate(Date eventEndDate) {
		this.eventEndDate = eventEndDate;
	}

	public String getEventDescription() {
		return eventDescription;
	}

	public void setEventDescription(String eventDescription) {
		this.eventDescription = eventDescription;
	}

	public User getOrganizer() {
		return organizer;
	}

	public void setOrganizer(User organizer) {
		this.organizer = organizer;
	}

	public Country getEventCountry() {
		return eventCountry;
	}

	public void setEventCountry(Country eventCountry) {
		this.eventCountry = eventCountry;
	}

	public City getEventCity() {
		return eventCity;
	}

	public void setEventCity(City eventCity) {
		this.eventCity = eventCity;
	}

	public String getEventAddress() {
		return eventAddress;
	}

	public void setEventAddress(String eventAddress) {
		this.eventAddress = eventAddress;
	}

	public EventAccess getEventAccess() {
		return eventAccess;
	}

	public void setEventAccess(EventAccess eventAccess) {
		this.eventAccess = eventAccess;
	}

	public Set<User> getParticipants() {
		return participants;
	}

	public void setParticipants(Set<User> participants) {
		this.participants = participants;
	}

	@Override
	public int hashCode() {
		return getEventId();
	}

	@Override
	public boolean equals(Object obj) {
		if (obj instanceof Event) {
			Event other = (Event) obj;
			return other.getEventId() == eventId;
		}
		return false;
	}

}
